#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <aclconio.h>
#include <define.h>
#include <transact.h>
#include <tran.h>
#include <gds.h>
#include <sizes.h>
#include "ConfProto.h"
#include "tblutil.h"
#include <\SOFTPAY\Ver30\source\include\sizes.h>
#include <\SOFTPAY\Ver30\HostSrc\citisrc\citiids.h>
#include <\SOFTPAY\Ver30\HostSrc\cpacsrc\cpacids.h>
#include <confio.h>

#include <\SOFTPAY\Ver30\source\include\CCT.h>



static void *storeFromStruct;

static int recordNum;
void registerCCT(void *ptr)
{
	 storeFromStruct = ptr;
}

void *dealWithAddressBoundary(void*address);
int	inLoadCCTRecFromStruct (int inRecNumber, void *vdStruct)
{
	int inRet;
	char* tmp = (char*)vdStruct;

	registerCCT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inLoadConfRec(CCT_FILENAME, SIZE_CCT_REC, inRecNumber, vdStruct);

	recordNum = inRecNumber;
	return inRet;
}

void vdRestoreCCTRecFromStruct(void *vdStruct)
{
	registerCCT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	memcpy((char *) pvdGetCCTRec(), vdStruct, SIZE_CCT_REC);

}

void vdCopyCCTRecFromStruct(void *vdStruct)
{
	registerCCT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
		memcpy(vdStruct, (char *) pvdGetCCTRec(), SIZE_CCT_REC);

}

int	inSaveCCTRecFromStruct (int inRecNumber,  void *vdStruct)
{
	int inRet;

	registerCCT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(CCT_FILENAME, SIZE_CCT_REC, inRecNumber, (char *) vdStruct);

	return inRet;
}

int	inUpdateCCTRecFromStruct (void *vdStruct)
{
	int inRet;

	registerCCT(vdStruct);
	vdStruct = dealWithAddressBoundary(vdStruct);
	inRet = inSaveConfRec(CCT_FILENAME, SIZE_CCT_REC, recordNum, (char *) vdStruct);

	return inRet;
}

short inGetTermCkrdrTypeFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return inGetTermCkrdrType();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((CCT_REC*)vdStruct)->inTermCkrdrType;
}

void vdSetTermCkrdrTypeFromStruct(short inTermCkrdrType, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetTermCkrdrType(inTermCkrdrType);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((CCT_REC*)vdStruct)->inTermCkrdrType = inTermCkrdrType;
}

char* szGetTermPortFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return szGetTermPort();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((CCT_REC*)vdStruct)->szTermPort;
}

void vdSetTermPortFromStruct(const char* szTermPort, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetTermPort(szTermPort);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	strNumCopy(((CCT_REC*)vdStruct)->szTermPort, szTermPort, sizeof(((CCT_REC*)NULL)->szTermPort)-1);
}

short inGetTermBaudFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return inGetTermBaud();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((CCT_REC*)vdStruct)->inTermBaud;
}

void vdSetTermBaudFromStruct(short inTermBaud, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetTermBaud(inTermBaud);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((CCT_REC*)vdStruct)->inTermBaud = inTermBaud;
}

short inGetTermFormatFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return inGetTermFormat();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((CCT_REC*)vdStruct)->inTermFormat;
}

void vdSetTermFormatFromStruct(short inTermFormat, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetTermFormat(inTermFormat);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((CCT_REC*)vdStruct)->inTermFormat = inTermFormat;
}

short inGetTermHandshakeFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return inGetTermHandshake();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((CCT_REC*)vdStruct)->inTermHandshake;
}

void vdSetTermHandshakeFromStruct(short inTermHandshake, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetTermHandshake(inTermHandshake);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((CCT_REC*)vdStruct)->inTermHandshake = inTermHandshake;
}

short inGetCheckEntryModeFromStruct(void*vdStruct)
{
	if(vdStruct != storeFromStruct)
		return inGetCheckEntryMode();
	vdStruct = dealWithAddressBoundary(vdStruct);
	return ((CCT_REC*)vdStruct)->inCheckEntryMode;
}

void vdSetCheckEntryModeFromStruct(short inCheckEntryMode, void*vdStruct)
{
	if(vdStruct != storeFromStruct)
	{
		vdSetCheckEntryMode(inCheckEntryMode);
		return;
	}
	vdStruct = dealWithAddressBoundary(vdStruct);
	((CCT_REC*)vdStruct)->inCheckEntryMode = inCheckEntryMode;
}

